// 状态管理模块
const tableState = {
  operationHistory: [],

  saveState(table) {
    const state = {
      html: table.innerHTML,
      timestamp: Date.now(),
    };
    this.operationHistory.push(state);
    if (this.operationHistory.length > 20) {
      this.operationHistory.shift();
    }
  },

  undo(table) {
    if (this.operationHistory.length > 0) {
      const previousState = this.operationHistory.pop();
      table.innerHTML = previousState.html;
      // 清除所有单元格的样式
      const allCells = table.getElementsByTagName('td');
      Array.from(allCells).forEach(cell => {
        cell.classList.remove('selected');
        // // 移除可能存在的其他样式类
        // cell.removeAttribute('style');
      });
      return true;
    }
    return false;
  },
};
